/**
 * Created by double_c on 2017/3/8.
 */

;$(function () {
    $('.zpHideBtn').on('click', function() {
        $('.zPin').slideToggle();
    });


    /**
     * 找工作 开始搜索
     */
    $('.schoolStartSearch').on('click',function(){
        var schoolSearchWord = $('#schoolSearch input[type="text"]').val().trim();
        if(schoolSearchWord !== ''){
            if(window.location.pathname.split('/').length === 4){
                window.location.href = '/school/search/'+window.location.pathname.split('/')[2]+'/'+window.location.pathname.split('/')[3]+'/'+schoolSearchWord;
            } else if (window.location.pathname.split('/').length === 3) {
                window.location.href = '/school/search/'+window.location.pathname.split('/')[2]+'/'+schoolSearchWord;
            } else if (window.location.pathname.split('/').length === 2) {
                window.location.href = '/school/search/'+schoolSearchWord;
            }
        }
    });

    /**
     * 招聘信息 开始搜索
     */
    $('.zpSearchBtn').on('click',function(){
        var zpKeyword = $('#zpForm input[type="text"]').val().trim();
        if(zpKeyword !== '') {
            if(window.location.pathname.split('/').length === 4){
                window.location.href = '/zp/search/'+window.location.pathname.split('/')[2]+'/'+window.location.pathname.split('/')[3]+'/'+zpKeyword;
            } else if (window.location.pathname.split('/').length === 3) {
                window.location.href = '/zp/search/'+window.location.pathname.split('/')[2]+'/'+zpKeyword;
            } else if (window.location.pathname.split('/').length === 2) {
                window.location.href = '/zp/search/'+zpKeyword;
            }
        }
    });

    /**
     * 回车键 出发搜索
     */
    $(document).on('keypress',function(e){
        var searchWord = $('#schoolSearch input[type="text"]').val();
        var zpSearchKeyword = $('.zpKeyword').val();
        if(e.keyCode === 13 && searchWord !== '' && searchWord !== undefined) {
            if(window.location.pathname.split('/').length === 4){
                window.location.href = '/school/search/'+window.location.pathname.split('/')[2]+'/'+window.location.pathname.split('/')[3]+'/'+searchWord;
            } else if (window.location.pathname.split('/').length === 3) {
                window.location.href = '/school/search/'+window.location.pathname.split('/')[2]+'/'+searchWord;
            } else if (window.location.pathname.split('/').length === 2) {
                window.location.href = '/school/search/'+searchWord;
            }
        } else if (e.keyCode === 13 && zpSearchKeyword !== '' && zpSearchKeyword !== undefined){
            if(window.location.pathname.split('/').length === 4){
                window.location.href = '/zp/search/'+window.location.pathname.split('/')[2]+'/'+window.location.pathname.split('/')[3]+'/'+zpSearchKeyword;
            } else if (window.location.pathname.split('/').length === 3) {
                window.location.href = '/zp/search/'+window.location.pathname.split('/')[2]+'/'+zpSearchKeyword;
            } else if (window.location.pathname.split('/').length === 2) {
                window.location.href = '/zp/search/'+zpSearchKeyword;
            }
        }
    });


    /**
     * 收藏 动画
     */
    $(document).on('click','.jobsListDetailRight',function(){
        $(this).find('.collect img').attr('src','/img/heart.png');
    });

    $('#citySelect').on('click',function(){
        document.querySelector('.zp_city_change_name').style.boxShadow = '0 -2px 2px 1px #ddd';
    });
});